package comet.measure;

import comet.web.GoogleDistanceView;

public class GoogleDistanceCtrl {

	public static double getDistance(String firstTerm, String secondTerm) {
		
		double occurrenceOfFirstTerm = 0.0;
		double occurrenceOfSecondTerm = 0.0;
		double cooccurrence = 0.0;
 
		occurrenceOfFirstTerm=getDistance(firstTerm);
		occurrenceOfSecondTerm=getDistance(secondTerm);		 
		cooccurrence=getDistance(firstTerm+secondTerm);
		
		return cooccurrence/(occurrenceOfFirstTerm+occurrenceOfSecondTerm-cooccurrence);
	}
	
	private static double getDistance(String keyword) {
		double occurrenceOfTerm=0.0;
		//first, we have to check wether the term exists or not in the JPA DB
		// otherwise, we google it for the first time
		// run  query on the JPA DB
		// SELECT numberofOccurence from GoogleSearchResult where term=keyword
		//if()
			//double occurrenceOfTerm = from JPA DB
			// return occurrenceOfTerm;
		occurrenceOfTerm=GoogleDistanceView.getTermOccurence(keyword);
		return occurrenceOfTerm;
	}
	

}
